pandas add two string columns

28

# if both columns are strings, you can concatenate them directly
df["period"] = df["Year"] + df["quarter"]

# If one (or both) of the columns are not string typed, you should convert it 
# (them) first,
df["period"] = df["Year"].astype(str) + df["quarter"]
df = df['Day'].map(str) + '-' + df['Month'].map(str) + '-' + df['Year'].map(str)
df1 = df['1st Column Name'].map(str) + df['2nd Column Name'].map(str) + ...

Comments

Submit
0 Comments